package service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import dao.AdminDao;
import dao.LogDao;
import domain.User;
import domain.UserBean;

public class AdminServiceImpl implements AdminService {
	AdminDao adminDao;
	private LogDao  logDao;
	java.util.Date dd;
	public AdminDao getAdminDao() {
		return adminDao;
	}

	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}

	@Override
	public void insertAdmin(User user,String path){
		user.setCreateDate(new Date());
		adminDao.insertAdmin(user,path);
	}
	/*��η���1���У�0Ϊû��
	 * (non-Javadoc)
	 * @see service.AdminService#login(java.lang.String)
	 */
	@Override
	public int login(String account,String password){
		System.out.println("service��account"+account);
		if(adminDao.getUserByAccount(account,password).size()>=1){
			logDao.insertLoginLog(account);
			return 1;
		}else{
			return 0;
		}
	}
	/*������1Ϊ��,0Ϊ��
	 * (non-Javadoc)
	 * @see service.AdminService#register(java.lang.String)
	 */
	@Override
	public int register(String account){
		if(adminDao.getUserByAccount(account).size()>=1){
			return 1;
		}else{
			return 0;
		}
	}

	public LogDao getLogDao() {
		return logDao;
	}

	public void setLogDao(LogDao logDao) {
		this.logDao = logDao;
	}

	@Override
	public List<List> showIndex() {
		// TODO Auto-generated method stub
		List<List> ll = adminDao.showIndex();
		return ll;
	}

	@Override
	public User showPersonUser(int userId) {
		// TODO Auto-generated method stub
		return adminDao.getUserById(userId);
	}

	@Override
	public String updatePass(UserBean userbean) {
		// TODO Auto-generated method stub
		Map session = ActionContext.getContext().getSession();
		String acc = (String) session.get("acc");
		return adminDao.updatePass(userbean,acc);
	}
}
